﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame4
{
    public class SpriteManager
    {
        protected Texture2D Texture;
        public Vector2 Position = Vector2.Zero;
        public Color Color = Color.White;
        public Vector2 Origin;
        public float Rotation = 0f;
        public float Scale = 1f;
        public SpriteEffects SpriteEffect;
        protected Rectangle[,] Rectangles;
        protected int MaxFrameH = 0;
        protected int MaxFrameV = 0;
        public int tileHeight, tileWidth;

        public SpriteManager(Texture2D Texture, int framesH, int framesV)
        {
            this.Texture = Texture;
            MaxFrameH = framesH;
            MaxFrameV = framesV;
            tileWidth = Texture.Width / framesH;
            tileHeight = Texture.Height / framesV;
            Rectangles = new Rectangle[framesH, framesV];
            for (int i = 0; i < framesH; i++){
                for (int j = 0; j < framesV; j++)
                {
                    Rectangles[i,j] = new Rectangle(
                        i * tileWidth, j * tileHeight, tileWidth, tileHeight);
                }
            }
        }

        public Texture2D GetTexture()
        {
            return Texture;
        }
        public int GetMaxFrameH()
        {
            return MaxFrameH;
        }
        public int GetMaxFrameV()
        {
            return MaxFrameV;
        }

        public void Draw(SpriteBatch spriteBatch, int curFramesH, int curFramesV)
        {
            spriteBatch.Draw(Texture, Position, Rectangles[curFramesH, curFramesV],
                Color, Rotation, Origin, Scale, SpriteEffect, 0f);
        }
    }
}
